<template>
  <div class="overview">
    <div class="overview-header">
      <h2>数据概览</h2>
      <p>系统核心数据统计与分析</p>
    </div>
    
    <!-- 核心统计卡片 -->
    <div class="stats-cards">
      <div class="stat-card">
        <div class="stat-icon user-icon">
          <el-icon><User /></el-icon>
        </div>
        <div class="stat-content">
          <div class="stat-value">{{ userCount }}</div>
          <div class="stat-label">用户总数</div>
          <div class="stat-change positive">+12%</div>
        </div>
      </div>
      
      <div class="stat-card">
        <div class="stat-icon order-icon">
          <el-icon><ShoppingCart /></el-icon>
        </div>
        <div class="stat-content">
          <div class="stat-value">{{ orderCount }}</div>
          <div class="stat-label">订单总数</div>
          <div class="stat-change positive">+8%</div>
        </div>
      </div>
      
      <div class="stat-card">
        <div class="stat-icon revenue-icon">
          <el-icon><Money /></el-icon>
        </div>
        <div class="stat-content">
          <div class="stat-value">¥{{ revenue }}</div>
          <div class="stat-label">总收入</div>
          <div class="stat-change positive">+15%</div>
        </div>
      </div>
      
      <div class="stat-card">
        <div class="stat-icon product-icon">
          <el-icon><Goods /></el-icon>
        </div>
        <div class="stat-content">
          <div class="stat-value">{{ productCount }}</div>
          <div class="stat-label">商品总数</div>
          <div class="stat-change negative">-3%</div>
        </div>
      </div>
    </div>
    
    <!-- 图表区域 -->
    <div class="charts-section">
      <div class="chart-card">
        <div class="chart-header">
          <h3>用户增长趋势</h3>
          <el-select v-model="timeRange" class="time-selector">
            <el-option label="最近7天" value="7days"></el-option>
            <el-option label="最近30天" value="30days"></el-option>
            <el-option label="最近90天" value="90days"></el-option>
          </el-select>
        </div>
        <div class="chart-content">
          <div class="mock-chart line-chart">
            <div class="chart-line"></div>
            <div class="chart-points">
              <div class="point" style="left: 10%; bottom: 20%"></div>
              <div class="point" style="left: 25%; bottom: 35%"></div>
              <div class="point" style="left: 40%; bottom: 45%"></div>
              <div class="point" style="left: 55%; bottom: 60%"></div>
              <div class="point" style="left: 70%; bottom: 75%"></div>
              <div class="point" style="left: 85%; bottom: 80%"></div>
            </div>
          </div>
        </div>
      </div>
      
      <div class="chart-card">
        <div class="chart-header">
          <h3>销售数据分析</h3>
        </div>
        <div class="chart-content">
          <div class="mock-chart bar-chart">
            <div class="bars">
              <div class="bar" style="height: 60%"></div>
              <div class="bar" style="height: 80%"></div>
              <div class="bar" style="height: 45%"></div>
              <div class="bar" style="height: 90%"></div>
              <div class="bar" style="height: 70%"></div>
              <div class="bar" style="height: 85%"></div>
            </div>
          </div>
        </div>
      </div>
    </div>
    
    <!-- 用户管理模块 -->
    <div class="management-section">
      <div class="management-card">
        <div class="management-header">
          <h3>用户管理</h3>
          <el-button type="primary" size="small" @click="handleUserManagement">
            <el-icon><Plus /></el-icon>
            添加用户
          </el-button>
        </div>
        <div class="management-content">
          <div class="user-stats">
            <div class="stat-item">
              <div class="stat-number">{{ userCount }}</div>
              <div class="stat-desc">总用户数</div>
            </div>
            <div class="stat-item">
              <div class="stat-number">1,234</div>
              <div class="stat-desc">活跃用户</div>
            </div>
            <div class="stat-item">
              <div class="stat-number">89</div>
              <div class="stat-desc">新增用户</div>
            </div>
          </div>
          <div class="quick-actions-row">
            <el-button @click="handleUserList" size="small">
              <el-icon><UserFilled /></el-icon>
              用户列表
            </el-button>
            <el-button @click="handleUserRoles" size="small">
              <el-icon><Key /></el-icon>
              角色管理
            </el-button>
            <el-button @click="handleUserPermissions" size="small">
              <el-icon><Lock /></el-icon>
              权限设置
            </el-button>
          </div>
        </div>
      </div>
    </div>

    <!-- 商品管理模块 -->
    <div class="management-section">
      <div class="management-card">
        <div class="management-header">
          <h3>商品管理</h3>
          <el-button type="primary" size="small" @click="handleProductManagement">
            <el-icon><Plus /></el-icon>
            添加商品
          </el-button>
        </div>
        <div class="management-content">
          <div class="product-stats">
            <div class="stat-item">
              <div class="stat-number">{{ productCount }}</div>
              <div class="stat-desc">总商品数</div>
            </div>
            <div class="stat-item">
              <div class="stat-number">1,890</div>
              <div class="stat-desc">在售商品</div>
            </div>
            <div class="stat-item">
              <div class="stat-number">45</div>
              <div class="stat-desc">库存预警</div>
            </div>
          </div>
          <div class="quick-actions-row">
            <el-button @click="handleProductList" size="small">
              <el-icon><Shop /></el-icon>
              商品列表
            </el-button>
            <el-button @click="handleProductCategories" size="small">
              <el-icon><Menu /></el-icon>
              分类管理
            </el-button>
            <el-button @click="handleProductInventory" size="small">
              <el-icon><Box /></el-icon>
              库存管理
            </el-button>
          </div>
        </div>
      </div>
    </div>

    <!-- 快速操作 -->
    <div class="quick-actions">
      <h3>快速操作</h3>
      <div class="action-cards">
        <div class="action-card" @click="handleUserManagement">
          <el-icon><UserFilled /></el-icon>
          <span>用户管理</span>
        </div>
        <div class="action-card" @click="handleProductManagement">
          <el-icon><Shop /></el-icon>
          <span>商品管理</span>
        </div>
        <div class="action-card" @click="handleOrderManagement">
          <el-icon><DocumentCopy /></el-icon>
          <span>订单管理</span>
        </div>
        <div class="action-card" @click="handleSystemSettings">
          <el-icon><Setting /></el-icon>
          <span>系统设置</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts" name="overview">
import { ref, computed } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { User, ShoppingCart, Money, Goods, UserFilled, Shop, DocumentCopy, Setting, Plus, Key, Lock, Menu, Box } from '@element-plus/icons-vue'

const timeRange = ref('30days')
const router = useRouter()

const userCount = computed(() => '12,345')
const orderCount = computed(() => '8,967')
const revenue = computed(() => '1,234,567')
const productCount = computed(() => '2,456')

// 用户管理相关方法
const handleUserManagement = () => {
  router.push('/main/system/user')
  ElMessage.success('跳转到用户管理')
}

const handleUserList = () => {
  router.push('/main/system/user')
  ElMessage.success('跳转到用户列表')
}

const handleUserRoles = () => {
  router.push('/main/system/role')
  ElMessage.success('跳转到角色管理')
}

const handleUserPermissions = () => {
  router.push('/main/system/menu')
  ElMessage.success('跳转到权限设置')
}

// 商品管理相关方法
const handleProductManagement = () => {
  router.push('/main/product/goods')
  ElMessage.success('跳转到商品管理')
}

const handleProductList = () => {
  router.push('/main/product/goods')
  ElMessage.success('跳转到商品列表')
}

const handleProductCategories = () => {
  router.push('/main/product/category')
  ElMessage.success('跳转到分类管理')
}

const handleProductInventory = () => {
  router.push('/main/product/inventory')
  ElMessage.success('跳转到库存管理')
}

// 其他快速操作方法
const handleOrderManagement = () => {
  router.push('/main/order/list')
  ElMessage.success('跳转到订单管理')
}

const handleSystemSettings = () => {
  router.push('/main/system/settings')
  ElMessage.success('跳转到系统设置')
}
</script>

<style scoped>
.overview {
  padding: 20px;
  background: #f5f5f5;
  min-height: 100vh;
}

.overview-header {
  margin-bottom: 30px;
}

.overview-header h2 {
  margin: 0 0 8px 0;
  color: #1f2937;
  font-size: 28px;
  font-weight: 600;
}

.overview-header p {
  margin: 0;
  color: #6b7280;
  font-size: 14px;
}

.stats-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.stat-card {
  background: white;
  border-radius: 12px;
  padding: 24px;
  display: flex;
  align-items: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.stat-icon {
  width: 60px;
  height: 60px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 16px;
  font-size: 24px;
  color: white;
}

.user-icon {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.order-icon {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.revenue-icon {
  background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}

.product-icon {
  background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
}

.stat-content {
  flex: 1;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: #1f2937;
  margin-bottom: 4px;
}

.stat-label {
  font-size: 14px;
  color: #6b7280;
  margin-bottom: 8px;
}

.stat-change {
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 12px;
  display: inline-block;
}

.stat-change.positive {
  background: #dcfce7;
  color: #16a34a;
}

.stat-change.negative {
  background: #fee2e2;
  color: #dc2626;
}

.charts-section {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.chart-card {
  background: white;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.chart-header h3 {
  margin: 0;
  color: #1f2937;
  font-size: 18px;
  font-weight: 600;
}

.time-selector {
  width: 120px;
}

.chart-content {
  height: 200px;
  position: relative;
}

.mock-chart {
  width: 100%;
  height: 100%;
  position: relative;
}

.line-chart {
  background: linear-gradient(to top, rgba(79, 172, 254, 0.1) 0%, transparent 100%);
  border-radius: 8px;
}

.chart-line {
  position: absolute;
  top: 20%;
  left: 10%;
  right: 15%;
  bottom: 20%;
  background: linear-gradient(to right, #4facfe, #00f2fe);
  height: 3px;
  border-radius: 2px;
  transform: rotate(-10deg);
}

.chart-points {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

.point {
  position: absolute;
  width: 8px;
  height: 8px;
  background: #4facfe;
  border-radius: 50%;
  border: 2px solid white;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.bar-chart {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 20px;
}

.bars {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  height: 100%;
}

.bar {
  width: 30px;
  background: linear-gradient(to top, #f093fb, #f5576c);
  border-radius: 4px 4px 0 0;
  transition: all 0.3s ease;
}

.bar:hover {
  transform: scaleY(1.1);
}

.management-section {
  margin-bottom: 30px;
}

.management-card {
  background: white;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
}

.management-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}

.management-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid #f0f0f0;
}

.management-header h3 {
  margin: 0;
  color: #1f2937;
  font-size: 18px;
  font-weight: 600;
}

.management-content {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.user-stats,
.product-stats {
  display: flex;
  justify-content: space-around;
  gap: 20px;
}

.stat-item {
  text-align: center;
  flex: 1;
  padding: 16px;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
}

.stat-number {
  font-size: 24px;
  font-weight: 700;
  color: #1e293b;
  margin-bottom: 4px;
}

.stat-desc {
  font-size: 13px;
  color: #64748b;
  font-weight: 500;
}

.quick-actions-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.quick-actions-row .el-button {
  flex: 1;
  min-width: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid #e5e7eb;
  background: white;
  color: #374151;
  transition: all 0.2s ease;
}

.quick-actions-row .el-button:hover {
  background: #f3f4f6;
  border-color: #6366f1;
  color: #6366f1;
}

.quick-actions-row .el-button .el-icon {
  font-size: 16px;
}

.quick-actions {
  background: white;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.quick-actions h3 {
  margin: 0 0 20px 0;
  color: #1f2937;
  font-size: 18px;
  font-weight: 600;
}

.action-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.action-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.action-card:hover {
  background: #f3f4f6;
  border-color: #d1d5db;
}

.action-card .el-icon {
  font-size: 20px;
  color: #6b7280;
}

.action-card span {
  font-size: 14px;
  color: #374151;
  font-weight: 500;
}

@media (max-width: 768px) {
  .stats-cards {
    grid-template-columns: 1fr;
  }
  
  .charts-section {
    grid-template-columns: 1fr;
  }
  
  .action-cards {
    grid-template-columns: 1fr;
  }
  
  .user-stats,
  .product-stats {
    flex-direction: column;
    gap: 12px;
  }
  
  .quick-actions-row {
    flex-direction: column;
  }
  
  .quick-actions-row .el-button {
    min-width: auto;
  }
  
  .management-header {
    flex-direction: column;
    gap: 12px;
    align-items: stretch;
  }
}
</style>
